import 'package:color_dart/RgbaColor.dart';
import 'package:flutter/material.dart';

class Btn extends StatelessWidget {
  final Function press;
  final String title;
  final bool active;
  const Btn({Key key, this.press, this.title, this.active}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    if (active) {
      return GestureDetector(
        onTap: press,
        child: Container(
            margin: EdgeInsets.only(right: 8, bottom: 8),
            decoration: BoxDecoration(
              color: rgba(243, 247, 255, 1),
              border: Border.all(
                color: rgba(42, 125, 250, 0.43),
                width: 1,
              ),
              borderRadius: BorderRadius.circular(15),
            ),
            padding: EdgeInsets.symmetric(vertical: 8, horizontal: 11),
            child: Text(
              '$title',
              style: TextStyle(
                  fontSize: 13, color: rgba(42, 125, 250, 1), height: 1.1),
            )),
      );
    } else {
      return GestureDetector(
        onTap: press,
        child: Container(
            margin: EdgeInsets.only(right: 8, bottom: 8),
            decoration: BoxDecoration(
              color: rgba(255, 255, 255, 1),
              border: Border.all(
                color: rgba(221, 221, 221, 1),
                width: 1,
              ),
              borderRadius: BorderRadius.circular(15),
            ),
            padding: EdgeInsets.symmetric(vertical: 8, horizontal: 11),
            child: Text(
              '$title',
              style: TextStyle(
                  fontSize: 13, color: rgba(107, 107, 107, 1), height: 1.1),
            )),
      );
    }
  }
}

class CommentHead extends StatefulWidget {
  CommentHead({Key key}) : super(key: key);
  @override
  _CommentHeadState createState() => _CommentHeadState();
}

class _CommentHeadState extends State<CommentHead> {
  int activeIndex = 0;

  changeActive(int index) {
    print(index);
    setState(() {
      activeIndex = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      padding: EdgeInsets.only(top: 13, left: 16, right: 16),
      child: Wrap(
        children: [
          Btn(
            title: '全部(10)',
            active: activeIndex == 0,
            press: () => changeActive(0),
          ),
          Btn(
            title: '回复及时(10)',
            active: activeIndex == 1,
            press: () => changeActive(1),
          ),
          Btn(
            title: '建议有帮助(10)',
            active: activeIndex == 2,
            press: () => changeActive(2),
          ),
          Btn(
            title: '态度非常(10)',
            active: activeIndex == 3,
            press: () => changeActive(3),
          ),
          Btn(
            title: '讲解很清楚(10)',
            active: activeIndex == 4,
            press: () => changeActive(4),
          ),
          //  GestureDetector(
          //     onTap: press(1),
          //     child: Container(
          //         margin: EdgeInsets.only(right: 8, bottom: 8),
          //         decoration: BoxDecoration(
          //           color: rgba(243, 247, 255, 1),
          //           border: Border.all(
          //             color: rgba(42, 125, 250, 0.43),
          //             width: 1,
          //           ),
          //           borderRadius: BorderRadius.circular(15),
          //         ),
          //         padding: EdgeInsets.symmetric(vertical: 8, horizontal: 11),
          //         child: Text(
          //           '回复及时(105)',
          //           style: TextStyle(
          //               fontSize: 13, color: rgba(42, 125, 250, 1), height: 1.1),
          //         )),
          //   ),
        ],
      ),
    );
  }
}
